package com.nyist.util;

import java.io.UnsupportedEncodingException;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

import sun.misc.BASE64Encoder;

public class Md5Util {
	
	public static Boolean validatePass(String oldPass, String newPass) throws NoSuchAlgorithmException, UnsupportedEncodingException{
		if (EncoderByMd5(newPass).equals(oldPass)) {
			return true;
		} else {
			return false;
		}
	}
	
	  public static String EncoderByMd5(String str) throws NoSuchAlgorithmException, UnsupportedEncodingException {
		    
		    MessageDigest md5=MessageDigest.getInstance("MD5");
		    @SuppressWarnings("restriction")
			BASE64Encoder base64en = new BASE64Encoder();
		    
		    @SuppressWarnings("restriction")
			String newstr=base64en.encode(md5.digest(str.getBytes("utf-8")));
		    return newstr;
		  }

	
	public static void main(String[] args) {
		try {
			System.out.println(validatePass("psJuoBTWVBlCr0G5RpgDKw==","hb155482."));
		} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
}
